/**************************************************************************
 *                                                                        *
 *         Copyright (c) 2014 by Generalplus Inc.                         *
 *                                                                        *
 *  This software is copyrighted by and is the property of Generalplus    *
 *  Inc. All rights are reserved by Generalplus Inc.                      *
 *  This software may only be used in accordance with the                 *
 *  corresponding license agreement. Any unauthorized use, duplication,   *
 *  distribution, or disclosure of this software is expressly forbidden.  *
 *                                                                        *
 *  This Copyright notice MUST not be removed or modified without prior   *
 *  written consent of Generalplus Technology Co., Ltd.                   *
 *                                                                        *
 *  Generalplus Inc. reserves the right to modify this software           *
 *  without notice.                                                       *
 *                                                                        *
 *  Generalplus Inc.                                                      *
 *  No.19, Industry E. Rd. IV, Hsinchu Science Park                       *
 *  Hsinchu City 30078, Taiwan, R.O.C.                                    *
 *                                                                        *
 **************************************************************************/
#ifndef __drv_l2_DISPLAY_H__
#define __drv_l2_DISPLAY_H__

#include "driver_l1.h"

#define _DRV_L2_DISP	_DRV_L1_TFT2

// Selection DISDEV_TFT / DISDEV_HDMI_720P / DISDEV_HDMI_480P for display device
#define DISPLAY_DEVICE	DISDEV_TFT2

#define LCD_DRV_EN_TPO_TD025THD1	1
#define LCD_DRV_EN_AUO_A027DTN019	1
#define LCD_DRV_EN_ILITEK_9326_I80	1
#define LCD_DRV_EN_T43				1
#define LCD_DRV_EN_ST7735_I80		1
#define LCD_DRV_EN_ILITEK_9225_I80	1
#define LCD_DRV_ST7701S	1
#define LCD_DRV_EN_ILI9342C_SPI	1

typedef enum
{
	#if LCD_DRV_EN_TPO_TD025THD1
	LCD_TPO_TD025THD1,
	#endif
	#if LCD_DRV_EN_AUO_A027DTN019
	LCD_AUO_A027DTN019,
	#endif
	#if LCD_DRV_EN_ILITEK_9326_I80
	LCD_ILITEK_9326_I80,
	#endif
	#if LCD_DRV_EN_T43
	LCD_T43,
	#endif
	#if LCD_DRV_EN_ST7735_I80
	LCD_ST7735_I80,
	#endif
	#if LCD_DRV_EN_ILITEK_9225_I80
	LCD_ILI9225_I80,
	#endif
	#if LCD_DRV_ST7701S
	LCD_7701S,
	#endif
	#if LCD_DRV_EN_ILI9342C_SPI
	LCD_ILI9342C,
	#endif
	LCD_TOTAL,
#if  C_BOARD_TYPE == C_CLIENT_BOARD
	LCD_DEV = LCD_ILI9342C//LCD_7701S//LCD_ILI9225_I80//LCD_TPO_TD025THD1//LCD_T43
#else
	LCD_DEV = LCD_ILITEK_9326_I80
#endif
} LCD_DRV;

// data type
typedef enum
{
	DISDEV_TFT	= 0,
	DISDEV_TFT2,
	DISDEV_MAX
} DISP_DEV;

typedef enum
{
	DIS_TYPE_TFT	= 1,
	DIS_TYPE_TFT2,
	DIS_TYPE_MAX
} DISP_TYPE;

typedef enum
{
	DISP_FMT_GP420,
	DISP_FMT_RGB565,
	DISP_FMT_BGRG,
	DISP_FMT_GBGR,
	DISP_FMT_RGBG,
	DISP_FMT_GRGB,
	DISP_FMT_VYUV,
	DISP_FMT_YVYU,
	DISP_FMT_UYVY,
	DISP_FMT_YUYV,
	DISP_FMT_MAX
} DISP_FMT;

typedef enum
{
	UI_FMT_RGB1555		= 0,
	UI_FMT_PALETTE_4,
	UI_FMT_PALETTE_16,
	UI_FMT_PALETTE_256,
	UI_FMT_ARGB444,
	UI_FMT_MAX
} UI_FMT;

typedef enum
{
	TFT_ROT_NONE,
	TFT_ROT_RIGHT,
	TFT_ROT_LEFT,
	TFT_ROT_FLIP
} TFT_ROT;

typedef enum
{
	LCD_IFCE_RGB,
	LCD_IFCE_I80
} LCD_IFCE;

typedef enum
{
	LCD_BL_CTRL_CONSTANT,
	LCD_BL_CTRL_PWM
} LCD_BL_CTRL;

typedef struct DispCtrl_s
{
	INT16U		lcd_width;
	INT16U		lcd_height;
	INT16S		display_pos_x;
	INT16S		display_pos_y;
	INT16U		pip_width;
	INT16U		pip_height;
	INT16S		pip_pos_x;
	INT16S		pip_pos_y;
	INT32S		(*init) (void);
	INT32S		(*uninit) (void);
	LCD_BL_CTRL	lcd_bl_ctrl;
	INT32U		lcd_pwm_freq;
	INT8U		lcd_pwm_duty;
	DISP_FMT	tft_fmt;
	LCD_IFCE	lcd_ifce;
	TFT_ROT		tft_rot;
	INT16U		tft_width;
	INT16U		tft_height;
} DispCtrl_t;

typedef void (*TFT_ISR) (void);

extern INT32S	drv_l2_display_init(LCD_DRV lcd_dev);
extern void		drv_l2_display_uninit(void);
extern INT32S	drv_l2_display_start(DISP_DEV disp_dev, TFT_ISR isr);
extern INT32S	drv_l2_display_stop(DISP_DEV disp_dev);
extern INT16U	drv_l2_display_tft_width_get(void);
extern INT16U	drv_l2_display_tft_height_get(void);
extern INT32U	drv_l2_display_get_fmt(DISP_DEV disp_dev);
extern INT32S	drv_l2_display_update(DISP_DEV disp_dev, INT32U buffer);
extern INT32S	drv_l2_display_buffer_set(DISP_DEV disp_dev, INT32U buffer);
extern INT32S	drv_l2_display_buffer_update_state_get(DISP_DEV disp_dev, INT32U wait);
extern INT32S	drv_l2_display_UI_init(DISP_DEV disp_dev, DISP_FMT color_mode, INT8U blend_level, INT32U ui_addr, INT32U pal_addr);
extern INT32S	drv_l2_display_UI_uninit(DISP_DEV disp_dev);
extern INT32S	drv_l2_display_UI_update(DISP_DEV disp_dev, INT8U blend_level, INT32U ui_addr, INT32U pal_addr);
extern INT32S	drv_l2_display_UI_stop(void);
extern INT32S	drv_l2_ppu_isr_callback_set(void (*callback) (INT32U ppu_event));
extern void		drv_l2_display_rotator_set(DISP_DEV disp_dev, INT32U enable);
extern INT32S	drv_l2_display_buffer_init(DISP_DEV disp_dev, INT32U buffer);

extern INT32S	drv_l2_tft_buffer_set(INT32U buffer);
extern INT32U	drv_l2_tft_buffer_get(void);
extern void		drv_l2_tft_isr_set(TFT_ISR isr);
extern TFT_ISR	drv_l2_tft_isr_get(void);
extern void		drv_l2_tft_init(void);
extern void		drv_l2_tft_uninit(void);

extern void		drv_l2_tft_backlight_en_set(BOOLEAN enable);
extern DISP_FMT	drv_l2_display_tft_fmt_get(void);
extern TFT_ROT	drv_l2_display_tft_rot_get(void);
extern LCD_IFCE	drv_l2_display_lcd_ifce_get(void);
extern INT16U	drv_l2_display_pip_width_get(void);
extern INT16U	drv_l2_display_pip_height_get(void);
extern INT16U	drv_l2_display_pip_x_get(void);
extern INT16U	drv_l2_display_pip_y_get(void);
extern INT16U	drv_l2_display_frame_x_get(void);
extern INT16U	drv_l2_display_frame_y_get(void);


#endif //__drv_l2_DISPLAY_H__
